<!--#
var expected = value!"";
var buttonName = btnName!"上传图片";
-->


    <form action="/upload" method="post" enctype="multipart/form-data" id="form_${id}">

        <div class="layui-upload" id="upload-img-tag-container-${id}">
            <div class="layui-upload-list">
                <img id="show_${id}" class="layui-upload-img" alt="" style="width: 13.5em;height: 13.5em;border: 2px solid #BDBDBD;border-radius:10px;" src="${addr}"/>
                <p id="upload-img-tag-text${id}"></p>
            </div>

            <input type="file"  id="img_${id}" name="file" style="display: none"/>
        </div>
        <button type="button" class="layui-btn" id="upload-img-tag-button-${id}" onclick="doSubmitForm('#form_${id}','#img_${id}','#show_${id}')" style="width: 13.5em;display: none">${buttonName}</button>
    </form>

<script>

    var btn2 = document.getElementById('show_${id}');
    btn2.addEventListener('click',addpic, false); //鼠标单击的时候调用

    function addpic() {
        $('#img_${id}').click();
    }

    $("#img_${id}").change(function(){
        $('#upload-img-tag-button-${id}').click();
    });

    function doSubmitForm(form_id,img_id,show_id){

        var formData = new FormData($(form_id)[0])  //创建一个forData
        formData.append('file', $(img_id)[0].files[0]) //把file添加进去  name命名为file
        $.ajax({
            url: "/upload.do",
            data: formData,
            type: "POST",
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            dataType:"text",
            success: function(data) {
               //成功
               $(show_id).prop("src",data);
               $("#image").val(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                //失败
                Common.error("服务器错误， 请联系管理员");
            }
        })
    }



    layui.use('form', function () {
        var form = layui.form;
        form.verify({
            uploadImgVerify: function (value, item) {
                if (!value) {
                    return '请上传图片';
                }
            }
        });
    });
</script>
